#!/bin/bash
schoolCode=BJAF201
schoolName=清华附中
license=ITB=20190510-591b9f4a9973a93479b9384a96f4dc70
## 配置文件
mv /var/nas/$schoolCode/config /var/nas/$schoolCode/config.bak
cp -r /var/nas/model/config /var/nas/$schoolCode/
sed -i "s/{schoolCode}/$schoolCode/g" /var/nas/$schoolCode/config/common.properties
schoolKey=`cat /var/nas/$schoolCode/config.bak/common.properties | grep ibc.schoolKey | awk -F '=' '{print $2}'`
schoolNameUnicode=`/usr/local/bin/convert2unicode $schoolName`
schoolNameUnicodeParam=`echo $schoolNameUnicode | sed "s/\\\\u/\\\\\\\\u/g"`
sed -i "s/{schoolName}/$schoolNameUnicodeParam/g" /var/nas/$schoolCode/config/common.properties
sed -i "s/{schoolKey}/$schoolKey/g" /var/nas/$schoolCode/config/common.properties

globalBXIKey=`cat /var/nas/$schoolCode/config.bak/common.properties | grep bxi.globalBXIKey | awk -F '=' '{print $2}'`
sed -i "s/{globalBXIKey}/$globalBXIKey/g" /var/nas/$schoolCode/config/common.properties

userEncryptkey=`cat /var/nas/$schoolCode/config.bak/uic.properties | grep user.encrypt.key | awk -F '=' '{print $2}'`
sed -i "s/{userEncryptkey}/$userEncryptkey/g" /var/nas/$schoolCode/config/itb.properties 
echo "$license" >> /var/nas/$schoolCode/config/license.properties
schoolCodeLower=`echo $schoolCode | tr '[A-Z]' '[a-z]'`

# sql
mysqlPod=`kubectl get pod | grep $schoolCodeLower-mysql-m | awk '{print $1}'`
sed -i "s/{schoolCode}/$schoolCode/g" /var/nas/data/bxn-integrate.sql
kubectl exec $mysqlPod /bin/bash  /usr/local/data/bxn-integrate.sh
sed -i "s/$schoolCode/{schoolCode}/g" /var/nas/data/bxn-integrate.sql

# app
mv /var/nas/yaml/BJAF201/rc-app.json /var/nas/yaml/BJAF201/rc-app.json.bak
cp /var/nas/yaml/school/rc-app.json /var/nas/yaml/$schoolCode/rc-app.json
sed -i "s/{schoolCode}/$schoolCode/g" /var/nas/yaml/$schoolCode/rc-app.json
sed -i "s/{schoolCodeUpper}/$schoolCode/g" /var/nas/yaml/$schoolCode/rc-app.json
sed -i "s/{schoolCodeLower}/$schoolCodeLower/g" /var/nas/yaml/$schoolCode/rc-app.json
sed -i "s/{schoolName}/$schoolName/g" /var/nas/yaml/$schoolCode/rc-app.json

kubectl delete rc $schoolCodeLower-app
kubectl create -f /var/nas/yaml/$schoolCode/rc-app.json

